/*
 * @lc app=leetcode.cn id=155 lang=javascript
 *
 * [155] 最小栈
 */

// @lc code=start
/**
 * initialize your data structure here.
 */
var MinStack = function () {
  this.db = [];
};

/**
 * @param {number} x
 * @return {void}
 */
MinStack.prototype.push = function (x) {
  this.db.push(x);
};

/**
 * @return {void}
 */
MinStack.prototype.pop = function () {
  this.db.pop();
};

/**
 * @return {number}
 */
MinStack.prototype.top = function () {
  return this.db[this.db.length - 1];
};

/**
 * @return {number}
 */
MinStack.prototype.getMin = function () {
  const t = this.db;
  let min = 0;
  for (let i = 0; i < t.length; i++) {
    let current = t[i];
    if (current < min) min = current;
  }
  return min;
};

/**
 * Your MinStack object will be instantiated and called as such:
 * var obj = new MinStack()
 * obj.push(x)
 * obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.getMin()
 */

const obj = new MinStack();
obj.push();
obj.push(2);
obj.push(0);
obj.push(3);
console.log(obj.getMin());
obj.pop();
console.log(obj.getMin());
obj.pop();
console.log(obj.getMin());
obj.pop();
console.log(obj.getMin());
// @lc code=end
